package ua.epam.muzalevskiy.traction.configuretion;

import java.util.Locale;
import java.util.ResourceBundle;
import javax.servlet.ServletContext;
import org.apache.log4j.Logger;

/**
 * <code>PageViewConfigurer</code> configures resources that correspond to
 * pages text information display
 * 
 * @author Muzalevskiy Vitaliy
 */
public class PageViewConfigurer {
    // logger is used for logging PageViewConfigurer class
    private static Logger logger = Logger.getLogger(PageViewConfigurer.class);
    private static PageViewConfigurer instance;
    // resourceBundle is used to get resources from the specified properties file
    private ResourceBundle resourceBundle;
    private static Locale currentLocale = new Locale("en");
    // BUNDLE_NAME specifies the name of the properties file
    private static final String BUNDLE_NAME = "pageview";
    public static final String TRACTION_ROUTES = "TRACTION_ROUTES";
    public static final String REGISTRATION = "REGISTRATION";
    public static final String REGISTRATE = "REGISTRATE";
    public static final String REGISTRATION_FORM = "REGISTRATION_FORM";
    public static final String VIEW_SCHEDULE = "VIEW_SCHEDULE";
    public static final String ROUTE_INFORMATION = "ROUTE_INFORMATION";
    public static final String FIND_ROUTE = "FIND_ROUTE";
    public static final String TO_MAIN_PAGE = "TO_MAIN_PAGE";
    public static final String TO_ADMINISTRATION_PAGE = "TO_ADMINISTRATION_PAGE";
    public static final String SELECT_ROUTE = "SELECT_ROUTE";
    public static final String SCHEDULE = "SCHEDULE";
    public static final String ERROR = "ERROR";
    public static final String CREATE_NEW_ROUTE = "CREATE_NEW_ROUTE";
    public static final String CREATE_NEW_STOP = "CREATE_NEW_STOP";
    public static final String CREATE_NEW_VEHICLE = "CREATE_NEW_VEHICLE";
    public static final String ADD_STOP_TO_ROUTE = "ADD_STOP_TO_ROUTE";
    public static final String ADD_VEHICLE_TO_ROUTE = "ADD_VEHICLE_TO_ROUTE";
    public static final String ADMINISTRATION_PAGE = "ADMINISTRATION_PAGE";
    public static final String ADD = "ADD";
    public static final String ENTER_ROUTE_ID = "ENTER_ROUTE_ID";
    public static final String ENTER_VEHICLE_ID = "ENTER_VEHICLE_ID";
    public static final String ENTER_VEHICLE_NUMBER = "ENTER_VEHICLE_NUMBER";
    public static final String ENTER_VEHICLE_TYPE = "ENTER_VEHICLE_TYPE";
    public static final String BUS = "BUS";
    public static final String TROLLEYBUS = "TROLLEYBUS";
    public static final String TRAM = "TRAM";
    public static final String CREATE = "CREATE";
    public static final String ENTER_LOGIN = "ENTER_LOGIN";
    public static final String ENTER_PASSWORD = "ENTER_PASSWORD";
    public static final String ENTER_EMAIL = "ENTER_EMAIL";
    public static final String ENTERING_WITH_LOGIN = "ENTERING_WITH_LOGIN";
    public static final String VEHICLE_INTERVAL = "VEHICLE_INTERVAL";
    public static final String MINUTES = "MINUTES";
    public static final String STOPS_IT_GOES_THRU = "STOPS_IT_GOES_THRU";

    /**
     * Returns the only instance of the <code>PageViewConfigurer</code>
     * (Singleton pattern)
     *
     * @return instance of the <code>PageViewConfigurer</code>
     */
    public static PageViewConfigurer getInstance() {
        if (instance == null) {
            instance = new PageViewConfigurer();
            instance.resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
            logger.info("Resource bundle complete");
        }
        return instance;
    }

    /**
     * Changes current locale for the ResourceBundle properties file
     * @param locale locale for the properties file
     */
    public static void ChangeLocale(Locale locale) {
        currentLocale = locale;
        getInstance().resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
        logger.info("Locale changed");
    }

    /**
     * Returns appropriate String value by the specified property name
     * @param key property name
     * @return value by the specified property name
     */
    public String getProperty(String key) {
        return (String)resourceBundle.getObject(key);
    }
}
